import { ArticleVm } from '../vm/article.vm';
import { ArticleModel } from './../model/article.model';
import { AbstractBaseService } from './base.service';
export class ArticleService extends AbstractBaseService<ArticleModel, ArticleVm> {
    
    constructor() { 
        super('admin/article');
    }

    fromVmToModel(vm: ArticleVm): ArticleModel {
        const articleModel = new ArticleModel();
        let keys = Object.getOwnPropertyNames(articleModel);
        for (let key in vm) { 
            if (keys.indexOf(key) >= 0) { 
                (articleModel as any)[key] = (vm as any)[key];
            }
        }
        return articleModel;
    }

    fromModelToVm(model: ArticleModel): ArticleVm {
        const vm = new ArticleVm();
        let keys = Object.getOwnPropertyNames(vm);
        for (let key in model) {
            if (keys.indexOf(key) >= 0) { 
                (vm as any)[key] = (model as any)[key];
            }
        }
        return vm;
    }
}

export default new ArticleService();